/**
 * GameEngine Demo - 用于验证GameEngine实现的演示脚本
 */

import { GameEngine } from './GameEngine'

/**
 * 创建一个简单的演示来验证GameEngine功能
 */
export function createGameEngineDemo(): void {
  // 创建一个临时的canvas元素用于测试
  const canvas = document.createElement('canvas')
  canvas.id = 'demo-canvas'
  canvas.width = 800
  canvas.height = 400
  canvas.style.border = '1px solid #ccc'
  
  // 将canvas添加到页面中
  document.body.appendChild(canvas)
  
  try {
    // 创建GameEngine实例
    const gameEngine = new GameEngine({
      canvasId: 'demo-canvas',
      width: 800,
      height: 400,
      targetFPS: 60
    })
    
    console.log('✅ GameEngine created successfully')
    console.log('Canvas size:', gameEngine.getSize())
    console.log('Target FPS:', gameEngine.getCurrentFPS())
    
    // 测试游戏状态管理
    console.log('Initial state - Running:', gameEngine.isGameRunning(), 'Paused:', gameEngine.isGamePaused())
    
    // 启动游戏
    gameEngine.start()
    console.log('After start - Running:', gameEngine.isGameRunning(), 'Paused:', gameEngine.isGamePaused())
    
    // 暂停游戏
    setTimeout(() => {
      gameEngine.pause()
      console.log('After pause - Running:', gameEngine.isGameRunning(), 'Paused:', gameEngine.isGamePaused())
      
      // 恢复游戏
      setTimeout(() => {
        gameEngine.resume()
        console.log('After resume - Running:', gameEngine.isGameRunning(), 'Paused:', gameEngine.isGamePaused())
        
        // 停止游戏
        setTimeout(() => {
          gameEngine.stop()
          console.log('After stop - Running:', gameEngine.isGameRunning(), 'Paused:', gameEngine.isGamePaused())
          console.log('✅ GameEngine demo completed successfully')
          
          // 清理
          document.body.removeChild(canvas)
        }, 1000)
      }, 1000)
    }, 1000)
    
  } catch (error) {
    console.error('❌ GameEngine demo failed:', error)
  }
}

// 如果在浏览器环境中运行，自动执行演示
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
  // 等待DOM加载完成
  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', createGameEngineDemo)
  } else {
    createGameEngineDemo()
  }
}